package com.yixun.qfbao.model.enums;

import org.apache.commons.lang.StringUtils;

import java.io.Serializable;

public enum AgeRangeEnum implements Serializable {
	UNLIMITED("UNLIMITED", "不限", null),
	ZERO_TO_TWENTY("ZERO_TO_TWENTY", "20岁及以下", null),
	TWENTY_ONE_TO_THIRTY("TWENTY_ONE_TO_THIRTY", "21-30岁", null),
	THIRTY_ONE_TO_FORTY("THIRTY_ONE_TO_FORTY", "31-40岁", null),
	FORTY_ONE_TO_FIFTY("FORTY_ONE_TO_FIFTY", "41-50岁", null),
	FIFTY_ONE_TO_MORE("FIFTY_ONE_TO_MORE", "51岁及以上", null),
	;

	private final String no;
	private final String des;
	private final Enum parent;

	AgeRangeEnum(String no, String des, Enum parent) {
		this.no = no;
		this.des = des;
		this.parent = parent;
	}

	public String getNo() {
		return no;
	}

	public String getDes() {
		return des;
	}

	public Enum getParent() {
		return parent;
	}

	public static AgeRangeEnum getByDescription(String des) {
		if (StringUtils.isBlank(des)) {
			return null;
		}
		for (AgeRangeEnum menum : values()) {
			if (menum.getDes().equals(des)) {
				return menum;
			}
		}
		return null;
	}

	public static AgeRangeEnum getByNo(String no) {
		if (StringUtils.isBlank(no)) {
			return null;
		}
		for (AgeRangeEnum menum : values()) {
			if (menum.getNo().equals(no)) {
				return menum;
			}
		}
		return null;
	}

	public static String getNameByCode(String code) {
		if (!StringUtils.isEmpty(code)) {
			AgeRangeEnum anEnum = getByNo(code);
			if (anEnum != null) {
				return anEnum.getDes();
			} else {
				return null;
			}
		}
		return null;
	}
}
